﻿namespace NMA.Infrastructure.NHibernate.CriteriaExpression.Category.SearchCategory
{
    using NMA.Domain.Model.Contract;
    using NMA.Infrastructure.NHibernate.Container;
    using NMA.Infrastructure.DBC;

    public class SearchChainBuilder : ISearchChainBuilder
    {
        public ISearchFinderFactory SearchFinderFactory { get; private set; }

        public SearchChainBuilder() : this(IoC.GetInstance<ISearchFinderFactory>())
        {
        }

        internal SearchChainBuilder(ISearchFinderFactory searchFinderFactory)
        {
            SearchFinderFactory = searchFinderFactory;
        }

        public SearchCategoryCriteriaType GetSearchCategoryCriteria(CategorySearchCriteria model)
        {
            Check.Assert(SearchFinderFactory != null, "SearchFinderFactory is null");
            Check.Assert(model != null, "CategorySearchCriteria is null");

            var searchCategoryType = SearchFinderFactory.CreatedAllSearch()
            .SetFinder(SearchFinderFactory.CreatedIdSearch())
            .SetFinder(SearchFinderFactory.CreatedNameSearch())
            .SetFinder(SearchFinderFactory.CreatedCreatedUserSearch())
            .SetFinder(SearchFinderFactory.CreatedCreatedDateSearch())
            .SetFinder(SearchFinderFactory.CreatedIdAndNameSearch())
            .SetFinder(SearchFinderFactory.CreatedIdAndCreatedUserSearch())
            .SetFinder(SearchFinderFactory.CreatedIdAndCreatedDateSearch())
            .SetFinder(SearchFinderFactory.CreatedNameAndCreatedUserSearch())
            .SetFinder(SearchFinderFactory.CreatedNameAndCreatedDateSearch())
            .SetFinder(SearchFinderFactory.CreatedCreatedUserAndCreatedDateSearch())
            .SetFinder(SearchFinderFactory.CreatedIdAndNameAndCreatedUserSearch())
            .SetFinder(SearchFinderFactory.CreatedIdAndNameAndCreatedDateSearch())
            .SetFinder(SearchFinderFactory.CreatedIdAndCreatedUserAndCreatedDateSearch())
            .SetFinder(SearchFinderFactory.CreatedNameAndCreatedUserAndCreatedDateSearch())
            .SetFinder(SearchFinderFactory.CreatedIdAndNameAndCreatedUserAndCreatedDateSearch())
            .GetSearchCategoryType(model);

            return searchCategoryType;
        }
    }
}